package top.kiterunner.learning.data_structure;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

/**
 * AdorynZhao in Tencent-UESTC.
 * Source Code Created on 2017/7/21.
 */
public class IteratorTest {

    public static void main1(String[] args) {
        List<Integer> ilist = new ArrayList<>();

        ilist.add(10);
        ilist.add(1);
        ilist.add(8);
        ilist.add(9);
        ilist.add(102);

        Iterator<Integer> iter = ilist.iterator();
        int count = 0;
        try {
            while (iter.hasNext()) {
                Integer t = iter.next();
                count++;
                System.out.println("VALUE " + count + " : " + t);
                if (count == 2) {
                    ilist.add(12);
                }
            }
        } catch (Exception e) {
            System.out.println("EEEEEEEEE");
            e.printStackTrace();
            System.out.println("EEEEEEEEE");
        }
    }

    public static void main(String[] args) {
        ArrayList<Integer> list = new ArrayList<>();
        list.add(2);
        list.add(3);

        Iterator<Integer> iterator = list.iterator();
        while (iterator.hasNext()) {
            Integer in = iterator.next();
            System.out.println("Value = " + in);
            if (in == 3) {
                list.add(10);
            }
        }
    }
}
